<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    #ul li{
      background-color: #fff;
    }
  </style>
</head>
<body>
  <ul id="ul">
    <li>aaaaa</li>
    <li>bbbbb</li>
    <li>ccccc</li>
    <li>ddddd</li>
    <li>eeeee</li>
    <li>fffff</li>
  </ul>
  <script>
    //获取元素
    var ul = document.getElementById("ul");
    var lis = ul.children;
    console.log(lis)
    //循环一遍lis
    for(var i = 0; i < lis.length; i++){
      //事件委托("事件名称","事件函数")
      lis[i].addEventListener("click", function(){
        if(this.style.backgroundColor == "" || this.style.backgroundColor=="rgb(255, 255, 255)"){
          this.style.backgroundColor = "rgb(85, 85, 85)";
        }else{
          this.style.backgroundColor = "rgb(255, 255, 255)";

        }
      })
    }
    
  </script>
</body>
</html>